package com.buba.controller;

import com.buba.pojo.Branch;
import com.buba.pojo.Message;
import com.buba.service.BranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin(allowCredentials = "true", originPatterns = "*")
public class BranchController {

    @Autowired
    private BranchService branchService;


    @RequestMapping("/branch")
    public List<Branch> bran(){
        return branchService.bran();
    }

    @RequestMapping("/dell")
    public Message del(@RequestParam("branchId")
                       String branchId){
        int count = branchService.dell(branchId);
        if (count==0)
            return new Message(0,"删除失败");
        return new Message(1,"删除成功");
    }

    @RequestMapping("/ins")
    public Message ins(@RequestParam Map<String,Object> map){
        int count = branchService.ins(map);
        if (count==0)
            return new Message(0,"添加失败");
        return new Message(1,"添加成功");
    }

    @RequestMapping("/edit")
    public int edit(@RequestParam Map<String,Object> map){
        return branchService.edit(map);

    }



}
